Hi biskra!
Subscribe To Forums
NEW Tek-Tips Groups
Browse Forums
My Threads
Forum List
Keyword Search
Personal Profile
Tell A Friend
Log Out

Activity since last visit
Remove forum(s) from list
Programmers
Microsoft: Access Forms
Microsoft: Access Modules (VBA Coding)
Microsoft: Access Queries and JET SQL
Microsoft: Access Reports
Microsoft: Access Other topics
Perl
Code Internationalization


"Best Of Breed" Forums Add Stickiness To Your Site

(Download This Button Today!)

"...The forum looks great! You guys have done a fantastic job on arranging things there...Your site is very precise and fun to visit..."

TopXML
DevGuru
DevelopersDex
ASP Alliance
Programmers Heaven
VisualBuilder.com
SitePoint
Developer Fusion
Code Project
Zvon - Guide to XML
Tek-Tips Forums
Search partner sites

   Search  Advanced Search
 
Read
New Posts
Reply To
This Thread

E-mail It
 

Print It
 
Next
Thread
Helen267 (Programmer) Dec 11, 2003
I have a report which creates a text file for import into a financial system (not in Access) using the OutputTo command.  The import procedure requires that each line be no longer than 70 characters.  The field being imported is 1000 characters, so I have created a query which uses the Mid function to load 70 characters (consecutively) into separate fields.

This works fine, however the import function in the financial package does not put the fields back together as one long string, and some words are cut in half.

Does anyone have any code which can split my memo field into separate fields (to a maximum of 70 characters) but cutting at the nearest space, rather than in the middle of words?

Any help would be HUGELY appreciated!

Thank Helen267 for this valuable post!


Inappropriate post?
If so, Red Flag it!



Check out the FAQ
area for this forum!


Start Your Own Tek-Tips Group! Click Here!
redwoodly (Programmer) Dec 11, 2003
here's some handy dandy parsing functions that combined  and checking for the Len(s) should do it:


-------------------------------------------------
Function CountWords(S) As Integer
'
' Counts words in a string separated by 1 or more spaces
'
Dim WC As Integer, i As Integer, OnASpace As Integer
  If VarType(S) <> 8 Or Len(Trim(S)) = 0 Then
    CountWords = 0
    Exit Function
  End If
  WC = 0
  OnASpace = True
  For i = 1 To Len(S)
    If Mid(S, i, 1) = " " Then
      OnASpace = True
    Else
      If OnASpace Then
        OnASpace = False
        WC = WC + 1
      End If
    End If
  Next i
  CountWords = WC
End Function

-------------------------------------------

Function CutWord(S, Remainder)
'
' CutWord: returns the first word in S.
' Remainder: returns the rest.
'
Dim Temp, P As Integer
  Temp = Trim(S)
  P = InStr(Temp, " ")
  If P = 0 Then P = Len(Temp) + 1
  CutWord = Left(Temp, P - 1)
  Remainder = Trim(Mid(Temp, P + 1))
End Function

---------------------------------------

if you need more help...let me know.

Thank redwoodly for this valuable post!


Inappropriate post?
If so, Red Flag it!



Check out the FAQ
area for this forum!


redwoodly (Programmer) Dec 11, 2003
ps.  you'll have to modify both to fit your needs, such as CutWords should be modified to cutWords before len(s) = 70 then return the rest...
instead of cut the first word.



Thank redwoodly for this valuable post!


Inappropriate post?
If so, Red Flag it!



Check out the FAQ
area for this forum!


CajunCenturion (Programmer) Dec 12, 2003
Here is a simple function which accepts two parameters, the text string and the maximum length of a single line, and returns a collection of individual lines each less than or equal to the cut-off length.

Here is how you should call it:

Dim IndLines As New Collection
Dim TheString As String

TheString = "Now is the time for all good men to come to the aid of their country"
Set IndLines = SplitTheString(TheString, 25)

and here is the function

Private Function SplitTheString(rStr_InStr As String, rInt_CutOff As Integer) As Collection

   Dim lCol_IndLines       As Collection
   Dim lStr_WrkString      As String
   Dim lInt_SpaceLoc       As Integer
   
   Set lCol_IndLines = New Collection
   lStr_WrkString = Trim(rStr_InStr)
   Do While (Len(lStr_WrkString) > rInt_CutOff)
      lInt_SpaceLoc = InStrRev(lStr_WrkString, " ", rInt_CutOff + 1)
      If (lInt_SpaceLoc > 0) Then
         lCol_IndLines.Add Left(lStr_WrkString, (lInt_SpaceLoc - 1))
         lStr_WrkString = Mid(lStr_WrkString, (lInt_SpaceLoc + 1))
      Else
         lCol_IndLines.Add lStr_WrkString
         lStr_WrkString = vbNullString
      End If
   Loop
   If (Len(lStr_WrkString) > 0) Then
      lCol_IndLines.Add lStr_WrkString
   End If
   
   Set SplitTheString = lCol_IndLines

End Function

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


Thank CajunCenturion for this valuable post!


Inappropriate post?
If so, Red Flag it!



Check out the FAQ
area for this forum!


Helen267 (Programmer) Dec 14, 2003
Thanks very much for the responses so far - both look like they'll do what I want.  However, I'm pretty new to both Access and Visual Basic, and I haven't used Collections before.  How do I get the formatted lines back in to my report?  I have 15 fields, named Expr1 - Expr15?

Thanks

Helen

Thank Helen267 for this valuable post!


Inappropriate post?
If so, Red Flag it!



Check out the FAQ
area for this forum!


Click here to mark this thread for e-mail notification. E-mail This Thread  Top of
Page
Next
Thread
Tek-Tips Forums is Member Supported. Click Here to donate.
Home > Forums > Programmers > DBMS Packages > Microsoft: Access Reports Forum
Start your own
Tek-Tips Group Today!

Back To Microsoft: Access Reports

Click here to mark this thread for e-mail notification.

Who's Marked
This Thread?

Helen267
redwoodly
TomCologne

Those members who have been voted by their peers to be the most helpful in this forum over a period of the last 6 weeks
dhookom
CosmoKramer
SteveR77
RoyVidar
Blorf
cghoga
lupins46
randysmid
glalsop
Steve101
(Full List)

These are the most popular forums that members of this forum participate in
Microsoft: Access Forms
Microsoft: Access Other topics
Microsoft: Access Modules (VBA Coding)
Microsoft: Access Queries and JET SQL
Microsoft: Access Tables and Relationships
More

Before you start Have you answered this question before?
Write your own Microsoft: Access Reports FAQ and point Helen267 to it!
Step 1
Message
Step 2
Options
E-Mail Notification   Emoticons/Smileys   Process TGML   Signature
Step 3
Submit Post
    

Promoting, selling, recruiting and student posting
are not allowed in the forums.
Click here to find out why.

LINK TO THIS FORUM!
(Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum)
TITLE:     Microsoft: Access Reports Forum at Tek-Tips
URL:     http://www.tek-tips.com/gthreadminder.cfm/lev2/4/lev3/27/pid/703
DESCRIPTION:     Microsoft: Access Reports technical support forum and mutual help system for computer professionals. Selling and recruiting forbidden.